from aiogram import F
from aiogram_dialog import Dialog, Window
from aiogram_dialog.widgets.kbd import Back, Button, Cancel, Next

from poker_bot.core.models.enums.account import AccountStatus
from poker_bot.tg_bot.dialogs.extras import copy_start_data_to_ctx
from poker_bot.tg_bot.dialogs.getters.accounts import account_info_getter
from poker_bot.tg_bot.dialogs.getters.users import user_role_getter
from poker_bot.tg_bot.dialogs.widgets import LocaleText
from poker_bot.tg_bot.states import AccountDetailsSG

from .handlers import confirm_account

account_details_window = Window(
    LocaleText("account-overview"),
    LocaleText("account-id", account_id="{account_id}"),
    LocaleText("account-status", status="{status_value}"),
    LocaleText("account-user-username", username="{username}"),
    LocaleText("was-created", was_created="{was_created}"),
    Next(
        LocaleText("confirm-account-btn"),
        when=(F["user_is_admin"]) & (F["status"] == AccountStatus.on_moderation),
    ),
    Cancel(LocaleText("back-btn")),
    state=AccountDetailsSG.account_details,
    getter=(account_info_getter, user_role_getter),
)

confirm_account_window = Window(
    LocaleText("confirm-account-msg"),
    Button(
        LocaleText("confirm-btn"),
        id="confirm_account",
        on_click=confirm_account,
    ),
    Back(LocaleText("back-btn")),
    state=AccountDetailsSG.confirm_account,
)

account_details_dialog = Dialog(
    account_details_window,
    confirm_account_window,
    on_start=copy_start_data_to_ctx,
)
